package com.example.myapplication.slice;

import com.example.myapplication.ResourceTable;
import com.example.myapplication.beans.MonitorData;
import com.example.myapplication.utils.MyDialog;
import ohos.aafwk.ability.AbilitySlice;
import ohos.aafwk.content.Intent;
import ohos.agp.components.*;
import ohos.agp.utils.Color;

import java.util.Random;

public class TodayMonitorDataSlice extends AbilitySlice {

    private Text stableText;
    private Text balanceText;
    private Text coordinatedText;
    private ProgressBar stableProgress;
    private ProgressBar balanceProgress;
    private ProgressBar coordinatedProgress;
    private ProgressBar stableVerticalProgress;
    private ProgressBar balanceVerticalProgress;
    private ProgressBar coordinatedVerticalProgress;
    private ProgressBar independentVerticalProgress;
    private RoundProgressBar sumProgress;

    @Override
    protected void onStart(Intent intent) {
        super.onStart(intent);
        super.setUIContent(ResourceTable.Layout_today_monitor_data1);

        stableText = findComponentById(ResourceTable.Id_sum_stable_text);
        balanceText = findComponentById(ResourceTable.Id_sum_balance_text);
        coordinatedText = findComponentById(ResourceTable.Id_sum_coordinated_text);
        stableProgress = findComponentById(ResourceTable.Id_stable_progressBar);
        balanceProgress = findComponentById(ResourceTable.Id_balance_progressBar);
        coordinatedProgress = findComponentById(ResourceTable.Id_coordinated_progressBar);
        stableVerticalProgress = findComponentById(ResourceTable.Id_stable_vertical_progressBar);
        balanceVerticalProgress = findComponentById(ResourceTable.Id_balance_vertical_progressBar);
        coordinatedVerticalProgress = findComponentById(ResourceTable.Id_coordinated_vertical_progressBar);
        independentVerticalProgress = findComponentById(ResourceTable.Id_independent_vertical_progressBar);
        sumProgress = findComponentById(ResourceTable.Id_sum_roundProgress);


        Button yesterdayDataButton = findComponentById(ResourceTable.Id_yesterday_data_button1);
        Button historyDataButton = findComponentById(ResourceTable.Id_history_data_button1);
        Button todayBackIndexButton = findComponentById(ResourceTable.Id_today_back_index_button1);
        Component.ClickedListener listener = new Component.ClickedListener() {
            @Override
            public void onClick(Component component) {
                if (component == yesterdayDataButton) {
                    present(new YesterdayMonitorDataSlice(), new Intent());
                } else if (component == historyDataButton) {
                    present(new HistoryMonitorDataSlice(), new Intent());
                }else if (component == todayBackIndexButton){

                    MyDialog.showDialog(TodayMonitorDataSlice.this);
                    int sum = 0;

                    //综合评分
                    sum = MyDialog.monitorData.getBalanceData() + MyDialog.monitorData.getStableData() + MyDialog.monitorData.getCoordinatedData();
                    sumProgress.setProgressValue(sum);
                    if (sumProgress.getProgress() <= 180){
                        sumProgress.setProgressColor(new Color(Color.rgb(0xff,0x00,0x00)));
                    }else if (sumProgress.getProgress() > 180 && sumProgress.getProgress() <= 240){
                        sumProgress.setProgressColor(new Color(Color.rgb(0xff,0xff,0x00)));
                    }else {
                        sumProgress.setProgressColor(new Color(Color.rgb(0x00,0xff,0x00)));
                    }

                    stableText.setText("稳定性"+ MyDialog.monitorData.getStableData());
                    balanceText.setText("平衡性"+ MyDialog.monitorData.getBalanceData());
                    coordinatedText.setText("协调性"+ MyDialog.monitorData.getCoordinatedData());

                    //稳定性
                    stableProgress.setProgressValue(MyDialog.monitorData.getStableData());
                    stableProgress.setProgressHintText(MyDialog.monitorData.getStableData()+"");
                    if (stableProgress.getProgress()<=60){
                        stableProgress.setProgressColor(new Color(Color.rgb(0xff,0x00,0x00)));
                    }else if (stableProgress.getProgress()>60 && stableProgress.getProgress() <=80){
                        stableProgress.setProgressColor(new Color(Color.rgb(0xff,0xff,0x00)));
                    }else {
                        stableProgress.setProgressColor(new Color(Color.rgb(0x00,0xff,0x00)));
                    }

                    //平衡性
                    balanceProgress.setProgressValue(MyDialog.monitorData.getBalanceData());
                    balanceProgress.setProgressHintText(MyDialog.monitorData.getBalanceData()+"");
                    if (balanceProgress.getProgress() <= 60){
                        balanceProgress.setProgressColor(new Color(Color.rgb(0xff,0x00,0x00)));
                    }else if (balanceProgress.getProgress() > 60 && balanceProgress.getProgress() <= 80){
                        balanceProgress.setProgressColor(new Color(Color.rgb(0xff,0xff,0x00)));
                    }else {
                        balanceProgress.setProgressColor(new Color(Color.rgb(0x00,0xff,0x00)));
                    }

                    //协调性
                    coordinatedProgress.setProgressValue(MyDialog.monitorData.getCoordinatedData());
                    coordinatedProgress.setProgressHintText(MyDialog.monitorData.getCoordinatedData()+"");
                    if (coordinatedProgress.getProgress() <= 60){
                        coordinatedProgress.setProgressColor(new Color(Color.rgb(0xff,0x00,0x00)));
                    }else if (coordinatedProgress.getProgress() > 60 && coordinatedProgress.getProgress() <= 80){
                        coordinatedProgress.setProgressColor(new Color(Color.rgb(0xff,0xff,0x00)));
                    }else {
                        coordinatedProgress.setProgressColor(new Color(Color.rgb(0x00,0xff,0x00)));
                    }

                    //条形图
                    stableVerticalProgress.setProgressValue(new Random().nextInt(101));
                    stableVerticalProgress.setProgressHintText(stableVerticalProgress.getProgress()+"");
                    balanceVerticalProgress.setProgressValue(new Random().nextInt(101));
                    balanceVerticalProgress.setProgressHintText(balanceVerticalProgress.getProgress()+"");
                    coordinatedVerticalProgress.setProgressValue(new Random().nextInt(101));
                    coordinatedVerticalProgress.setProgressHintText(coordinatedVerticalProgress.getProgress()+"");
                    independentVerticalProgress.setProgressValue(new Random().nextInt(101));
                    independentVerticalProgress.setProgressHintText(independentVerticalProgress.getProgress()+"");


                }
            }
        };
        yesterdayDataButton.setClickedListener(listener);
        historyDataButton.setClickedListener(listener);
        todayBackIndexButton.setClickedListener(listener);

    }

}
